#LoginRequiredMixin 未登陆的用户会返回 重定向 重定向并不是JSON数据
#我们需要  返回JSON数据
# 用户中心，也必须是登录用户
from django.contrib.auth.mixins import AccessMixin
# class LoginRequiredJSONMixin(AccessMixin):
#     """Verify that the current user is authenticated."""
#
#     def dispatch(self, request, *args, **kwargs):
#         if not request.user.is_authenticated:
#             return JsonResponse({'code':400,'errmsg':'用户未登录'})
#         return super().dispatch(request, *args, **kwargs)

from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import JsonResponse


class LoginRequiredJSONMixin(LoginRequiredMixin):
    def handle_no_permission(self):
        return JsonResponse({'code':400,'errmsg':'用户未登录'})
